package cn.tansanqinger.dao.nosql.impl;

import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;

import cn.tansanqinger.dao.nosql.IVerificationCode;

@Controller("verificationCodeImpl")
public class VerificationCodeImpl implements IVerificationCode {

	@Autowired
	private StringRedisTemplate redisTemplate;
	
	@Override
	public void saveEmailMessageNoSQL(String key, String value) {
		redisTemplate.opsForValue().set(key, value, 60*5, TimeUnit.SECONDS);
	}

	@Override
	public String readEmailMessageNoSQL(String key) {
		String message = redisTemplate.opsForValue().get(key);
		redisTemplate.delete(key);
		return message;
	}

	@Override
	public boolean removeEmailMessageNoSQL(String key) {
		return redisTemplate.delete(key);
	}
}
